home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / intuisup.lha / Intuisup / source.lha / Menus / menus_test.c < prev    next >
C/C++ Source or Header  |  1992-07-28  |  7KB  |  217 lines

  1. /* $Revision Header *** Header built automatically - do not edit! ***********
  2.  *
  3.  *    (C) Copyright 1991 by Torsten Jürgeleit
  4.  *
  5.  *    Name .....: menus_test.c
  6.  *    Created ..: Thursday 19-Dec-91 18:03:07
  7.  *    Revision .: 2
  8.  *
  9.  *    Date        Author                 Comment
  10.  *    =========   ====================   ====================
  11.  *    11-Jul-92   Torsten Jürgeleit      now get pointer to console device
  12.  *    03-Jun-92   Torsten Jürgeleit      alternate color for menu item texts
  13.  *    19-Dec-91   Torsten Jürgeleit      Created this file!
  14.  *
  15.  ****************************************************************************
  16.  *
  17.  *    Test of menu support functions
  18.  *
  19.  * $Revision Header ********************************************************/
  20.  
  21.     /* Includes */
  22.  
  23. #include <exec/types.h>
  24. #include <graphics/gfxbase.h>
  25. #include <graphics/text.h>
  26. #include <intuition/intuitionbase.h>
  27. #include <intuition/intuition.h>
  28. #ifdef AZTEC_C
  29. #include <functions.h>   /* needed for Aztec C - prototypes and pragmas for all Amiga system functions */
  30. #endif
  31. #include <libraries/memwatch.h>   /* header file for memory debug link library (Fish 240) - AFTER functions.h */
  32. #include "/render/render.h"
  33. #include "/texts/texts.h"
  34. #include "menus.h"
  35.  
  36.     /* Defines */
  37.  
  38. #define WINDOW_WIDTH        600
  39. #define WINDOW_HEIGHT        180
  40. #define WINDOW_IDCMP        (CLOSEWINDOW | MENUPICK)
  41. #define WINDOW_FLAGS        (WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH | SMART_REFRESH | NOCAREREFRESH | ACTIVATE)
  42. #define WINDOW_TITLE        (UBYTE *)" Menus test "
  43.  
  44. #define RENDER_INFO_FLAGS    (USHORT)(RENDER_INFO_FLAG_INNER_WINDOW | RENDER_INFO_FLAG_BACK_FILL)
  45. #define OPEN_WINDOW_FLAGS    (USHORT)(OPEN_WINDOW_FLAG_CENTER_SCREEN | OPEN_WINDOW_FLAG_RENDER_PENS)
  46.  
  47. #define MESSAGE1_TEXT        "Select menu item"
  48. #define MESSAGE1_TOP_EDGE    60
  49. #define MESSAGE1_TEXT_ATTR    &topaz60_attr
  50.  
  51. #define MESSAGE2_TEXT        "Menu no. %d menu item no. %d sub item no. %d selected"
  52. #define MESSAGE2_TOP_EDGE    120
  53. #define MESSAGE2_TEXT_ATTR    &topaz80_attr
  54.  
  55.     /* Globals */
  56.  
  57. struct IntuitionBase  *IntuitionBase;
  58. struct GfxBase        *GfxBase;
  59. struct Library        *DiskfontBase;
  60. struct Library        *LayersBase;
  61. struct Device         *ConsoleDevice;
  62.  
  63.     /* Statics */
  64.  
  65. STATIC struct NewWindow  test_new_window = {
  66.    0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, WINDOW_IDCMP, WINDOW_FLAGS,
  67.    NULL, NULL, WINDOW_TITLE, NULL, NULL, 0, 0, 0, 0, WBENCHSCREEN
  68. };
  69. STATIC struct TextAttr  topaz80_attr = { (STRPTR)"topaz.font", TOPAZ_EIGHTY,
  70.                            FS_NORMAL, FPF_ROMFONT },
  71.             topaz60_attr = { (STRPTR)"topaz.font", TOPAZ_SIXTY,
  72.                            FS_NORMAL, FPF_ROMFONT };
  73.     /* Defines for test menus */
  74.  
  75. #define TEST_MENU_TEXT_ATTR    &topaz60_attr
  76.  
  77.     /* Statics for test menus */
  78.  
  79. STATIC struct MenuData  test_menu_data[] = {
  80.    {
  81.     MENU_DATA_TYPE_TITLE, 0, "Menu 0", NULL, 0
  82.    }, {
  83.        MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_ATTRIBUTE | MENU_DATA_FLAG_SELECTED, "Item 0.0", "0", ~(1L << 0)
  84.    }, {
  85.  
  86.        MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_ATTRIBUTE, "Item 0.1", "1", ~(1L << 1)
  87.    }, {
  88.        MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_HIGH_BOX, "Item 0.2", NULL, 0
  89.    }, {
  90.           MENU_DATA_TYPE_SUBITEM, 0, "Item 0.2.0", "A", 0
  91.    }, {
  92.           MENU_DATA_TYPE_SUBITEM, 0, "Item 0.2.1", "B", 0
  93.    }, {
  94.        MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_TEXT_COLOR2, "Item 0.3", NULL, 0
  95.    }, {
  96.     MENU_DATA_TYPE_TITLE, 0, "Menu 1", NULL, 0
  97.    }, {
  98.        MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_HIGH_BOX, "Item 1.0", "C", 0
  99.    }, {
  100.        MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_EMPTY_LINE, "Item 1.1", "D", 0
  101.    }, {
  102.        MENU_DATA_TYPE_ITEM, 0, "Item 1.2", NULL, 0
  103.    }, {
  104.           MENU_DATA_TYPE_SUBITEM, 0, "Item 1.2.0", "E", 0
  105.    }, {
  106.           MENU_DATA_TYPE_SUBITEM, 0, "Item 1.2.1", "F", 0
  107.    }, {
  108.        MENU_DATA_TYPE_ITEM, 0, "Item 1.3", NULL, 0
  109.    }, {
  110.           MENU_DATA_TYPE_SUBITEM, 0, "Item 1.3.0", "G", 0
  111.    }, {
  112.           MENU_DATA_TYPE_SUBITEM, MENU_DATA_FLAG_EMPTY_LINE, "Item 1.3.1", "H", 0
  113.    }, {
  114.        MENU_DATA_TYPE_ITEM, MENU_DATA_FLAG_TEXT_COLOR2, "Item 1.4", "I", 0
  115.    }, {
  116.     INTUISUP_DATA_END        /* mark end of menu data */
  117.    }
  118. };
  119.     /* Prototypes */
  120.  
  121. VOID test_action(struct RenderInfo  *ri, struct Window  *win,
  122.                               struct MenuList  *ml);
  123.     /* Pragmas */
  124.  
  125. #pragma regcall(test_action(a0,a1,a2))
  126.  
  127.     /* Menus test */
  128.  
  129.    LONG
  130. main(VOID)
  131. {
  132.    struct IOStdReq    io;
  133.    struct RenderInfo  *ri;
  134.    struct Window      *win;
  135.    struct MenuList    *ml;
  136.  
  137.    MWInit((BPTR)NULL, 0L);
  138.    if (IntuitionBase = OpenLibrary("intuition.library", 0L)) {
  139.       if (GfxBase = OpenLibrary("graphics.library", 0L)) {
  140.      if (DiskfontBase = OpenLibrary("diskfont.library", 0L)) {
  141.         if (LayersBase = OpenLibrary("layers.library", 0L)) {
  142.            if (!OpenDevice("console.device", -1L,
  143.                          (struct IORequest *)&io, 0L)) {
  144.           ConsoleDevice = io.io_Device;
  145.           if (ri = get_render_info(NULL, RENDER_INFO_FLAGS)) {
  146.              if (win = open_window(ri, &test_new_window,
  147.                                OPEN_WINDOW_FLAGS)) {
  148.             print_text(ri, win, MESSAGE1_TEXT, 0,
  149.                      MESSAGE1_TOP_EDGE, TEXT_DATA_TYPE_TEXT,
  150.                  TEXT_DATA_FLAG_CENTER, MESSAGE2_TEXT_ATTR);
  151.             if (ml = create_menu(ri, win, &test_menu_data[0],
  152.                            TEST_MENU_TEXT_ATTR, NULL)) {
  153.                attach_menu(win, ml);
  154.                test_action(ri, win, ml);
  155.                remove_menu(ml);
  156.                free_menu(ml);
  157.             }
  158.             close_window(win, FALSE);
  159.             }
  160.             free_render_info(ri);
  161.           }
  162.           CloseDevice((struct IORequest *)&io);
  163.            }
  164.            CloseLibrary(LayersBase);
  165.         }
  166.         CloseLibrary(DiskfontBase);
  167.      }
  168.      CloseLibrary(GfxBase);
  169.       }
  170.       CloseLibrary(IntuitionBase);
  171.    }
  172.    MWTerm();
  173.    return(0L);
  174. }
  175.     /* Perform IDCMP action */
  176.  
  177.    VOID
  178. test_action(struct RenderInfo  *ri, struct Window  *win, struct MenuList  *ml)
  179. {
  180.    struct MsgPort  *up = win->UserPort;
  181.    BOOL keepon = TRUE;
  182.  
  183.    do {
  184.       struct IntuiMessage  *msg;
  185.  
  186.       WaitPort(up);
  187.       while (msg = (struct IntuiMessage *)GetMsg(up)) {
  188.      ULONG  class = msg->Class;
  189.      USHORT code  = msg->Code;
  190.  
  191.      ReplyMsg((struct Message *)msg);
  192.      switch (class) {
  193.         case CLOSEWINDOW :
  194.            keepon = FALSE;
  195.            break;
  196.  
  197.         case MENUPICK :
  198.            while (code != MENUNULL) {
  199.           BYTE buffer[80];
  200.  
  201.           sprintf(&buffer[0], MESSAGE2_TEXT,
  202.                   (MENUNUM(code) != NOMENU ? MENUNUM(code) : 0),
  203.                   (ITEMNUM(code) != NOITEM ? ITEMNUM(code) : 0),
  204.                 (SUBNUM(code) != NOSUB ? SUBNUM(code) : 0));
  205.           clear_window(ri, win, 0, MESSAGE2_TOP_EDGE, WINDOW_WIDTH,
  206.                                      10, 0);
  207.           print_text(ri, win, &buffer[0], 0, MESSAGE2_TOP_EDGE,
  208.                 TEXT_DATA_TYPE_TEXT, TEXT_DATA_FLAG_CENTER |
  209.                  TEXT_DATA_FLAG_COLOR2, MESSAGE2_TEXT_ATTR);
  210.           code = menu_item_address(ml, code)->NextSelect;
  211.            }
  212.            break;
  213.      }
  214.       }
  215.    } while (keepon == TRUE);
  216. }
  217.